<template>
  <wx-tables
    :columns="columns"
    title="费用类型维护"
    :data-source="dataSource"
    :loading="loading"
    :total="total"
    :size.sync="size"
    :page.sync="page"
  >
    <!-- tools -->
    <template #tools>
      <el-button type="primary" class="table-btn" icon="el-icon-plus" @click="handleOpenForm()">新增</el-button>
      <el-button class="table-btn" icon="el-icon-refresh-right" @click="handleGetTable">刷新</el-button>
    </template>
    <!-- table slots -->
    <template v-slot:type="{ row }">
      <span>{{ TYPES[row.type ] }}</span>
    </template>
    <template v-slot:status="scope">
      <el-switch
        v-model="scope.row.status"
        :active-value="1"
        :inactive-value="0"
        active-color="#13ce66"
        @change="(val) => handleSwitchStatus(val, scope.row.id, scope.$index)"
      />
    </template>
    <template v-slot:oper="record">
      <div class="oper-box">
        <span><el-link type="primary" @click="handleOpenForm(record.row.id)">编辑</el-link></span>
        <el-popconfirm
          :ref="`popover-${record.$index}`"
          title="确定删除当前所选项吗？"
          @confirm="handleDelByKey(record.row.id)"
        >
          <el-link slot="reference" type="danger">删除</el-link>
        </el-popconfirm>
      </div>
    </template>
    <wx-dialog
      ref="wx-dialog"
      :visible.sync="formVisible"
      :is-add="isAdd"
      width="500px"
      @ok="handleSaveForm"
    >
      <el-form ref="ruleForm" v-loading="formLoading" :rules="ruleForm" :model="formInfo" label-position="left" label-width="130px">
        <el-form-item label="测试">
          <el-input v-model="formInfo.name" />
        </el-form-item>
        <el-form-item label="测试">
          <el-input v-model="formInfo.name2" />
        </el-form-item>
        <el-form-item label="测试">
          <el-input v-model="formInfo.name3" />
        </el-form-item>
        <el-form-item label="测试">
          <el-input v-model="formInfo.name4" />
        </el-form-item>
      </el-form>
    </wx-dialog>
  </wx-tables>
</template>

<script>
// 普通弹窗
const TYPES = {
  0: '租金类',
  1: '其他费用类'
}
import WxDialog from '@/components/WxDialog'
import WxTables from '@/components/WxTables'
import TableMixins from '@/components/WxTables/mixins'
export default {
  name: 'A',
  components: {
    WxDialog,
    WxTables
  },
  mixins: [TableMixins],
  data() {
    return {
      columns: [
        { dataIndex: 'code', label: '费用类型编码' },
        { dataIndex: 'name', label: '费用类型名称' },
        { dataIndex: 'type', label: '费用类型', slots: true },
        { dataIndex: 'status', label: '启用', slots: true },
        { dataIndex: 'remark', label: '备注' },
        { dataIndex: 'oper', label: '操作', slots: true }
      ],
      markId: 'id',
      // 查询表格API
      // api: '/systemAdmin/getListByCon',
      // 根据ID markId 查询
      // findApi: '/systemAdmin/getById',
      // 接口前缀 修改
      baseApi: '/systemManagement/',
      ruleForm: {
        name: [
          { required: true, trigger: 'blur', message: '请输入费用类型名称' }
        ]
      },
      TYPES: Object.freeze(TYPES)
    }
  }
}
</script>
